<template>
    <view>
               
        <VoteList :type="query.type" :status="status" :list="voteList" />
        <view class="app-bottom-paddig"></view>
    </view>
</template>
<script>
import VoteList from '@/components/VoteList/index.vue'
import { getVoteList } from '@/api/index'
import {
		mapState,
	
	} from 'vuex'
import { parseSceneParams } from '@/util/function'
export default {
    name: 'VotingList',
    components: {
        VoteList
    },
    data() {
        return {
            voteList:[],
            total:0,
            status:'loadmore',
            query:{
                pageNum:1,
                pageSize:10,
                type:0
            }
        }
    },
    computed: {
         ...mapState("community",[
          "communityId"
    ])
    },
    onLoad(options) {
       
        this.init(options)
       
    },
    onPullDownRefresh() {
        this.refreshPage()
    },
    	onReachBottom(){
			if(this.voteList.length<this.total){
				this.status='loading'
				this.query.pageNum++
				this.getVoteList()
			}else{
				this.status='nomore'
			}
		},
        methods: {
            setTitle(type){
                if(type==1){
                   uni.setNavigationBarTitle({
                    title: "业主大会投票"
                   })
                }else if(type==2){
                    uni.setNavigationBarTitle({
                        title: "快速决议"
                    })
                }else if(type==3){
                    uni.setNavigationBarTitle({
                        title: "问卷调查"
                    })
                }else if(type==4){
                    uni.setNavigationBarTitle({
                        title: "倡议书"
                    })
                }
            },
            init(options){
                    if(options.scene){
                        options=parseSceneParams(options)
                        if(options.type){
                            this.query.type=options.type
                        }
                        if(options.communityId){
                            this.$store.commit("community/setCommunityId",options.communityId)
                        }
                       
                    }else if(options.type){
                        this.query.type=options.type
                        this.setTitle(options.type)
                        if(options.communityId){
                            this.$store.commit("community/setCommunityId",options.communityId)
                        }
                    }
                    this.$nextTick(()=>{
                        this.getVoteList()
                    })
            },
          async getVoteList() {
				let data=await getVoteList( {communityId:this.communityId,
				pageNum:this.query.pageNum,
				pageSize:this.query.pageSize,
                type:this.query.type
                } )
				this.voteList =[...this.voteList,...data.rows]
				this.total=data.total
                if(this.voteList.length>=this.total){
                    this.status='nomore'
                }else{
                    this.status='loadmore'
                }
				
			},
            async refreshPage() {
                // Reset pagination
                this.query.pageNum = 1
                this.voteList = []
                this.total = 0
                this.status = 'loadmore'
                
                // Refresh data
                await this.getVoteList()
                
                // Stop pull-down refresh animation
                uni.stopPullDownRefresh()
                
                // Show success message
                
            },
        }
}
</script>
<style scoped>
</style>